package com.gastudio.Protocol;

import org.apache.mina.core.session.IoSession;
import org.apache.mina.filter.codec.*;

import java.nio.charset.Charset;

/**
 * 协议工厂【获得自定义编解码器】
 * Created by 余艾龙 on 2017/6/21.
 */
public class ProtocolFactory implements ProtocolCodecFactory{
    private final ProtocolDecoder decoder;
    private final ProtocolEncoder encoder;
    public ProtocolFactory(Charset charset){
        encoder=new ProtocolEncoder(charset);
        decoder=new ProtocolDecoder(charset);
    }
    @Override
    public ProtocolEncoder getEncoder(IoSession ioSession) throws Exception {
        return encoder;
    }

    @Override
    public ProtocolDecoder getDecoder(IoSession ioSession) throws Exception {
        return decoder;
    }
}
